<?php

/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/15
 * Time: 9:24
 */

namespace App\Services\Api;

use App\admin\Service\OA;
use App\Jobs\Fun;
use App\Models\Admin\OrderBaleModel;
use App\Models\Admin\OrderCheckModel;
use App\Models\Admin\OrderTempModel;
use App\Models\LogModel;
use App\Models\Main\MsgSysModel;
use App\Models\OrderCommentModel;
use App\Services\OrdersPayService;
use Illuminate\Http\Request;
use App\Models\MoneyBilModel;
use DB;
use App\Models\User\UserOrdersModel;
use App\Services\Msg\MsgService;

/// App\Services\Api\CallMsg@
class CallMsg extends ApiBase
{

    public function getCallMsg(Request $request)
    {
        $myId = OA::$user->getId();
        $duifang = $request->input('uid');
        $maxid = $request->input('maxid');
        $msg = new MsgService;
        $msg->adduid($duifang);
        $msg->adduid($myId);
        $msg->clearCount($myId, $duifang);

        $msg->load();
        OA::Json(0, [
            'newlist' => $msg->getNewlist($maxid),
            'maxid' => $msg->getmaxid()
        ]);
    }


    public function CallSendMsg(Request $request)
    {
        $myId = OA::$user->getId();
        $duifang = $request->input('uid');
        $quest = $request->input('quest');
        $maxid = $request->input('maxid');
        $msg = new MsgService;
        $msg->adduid($duifang);
        $msg->adduid($myId);
        $msg->load();
        $msg->send($duifang, $quest);
        OA::Json(0, [
            'newlist' => $msg->getNewlist($maxid),
            'maxid' => $msg->getmaxid()
        ]);
    }

    /**
     * 获取未读的消息列表
     * 返回用户列表 包括用户头像,名字,消息数量
     */
    public function getmsglist(Request $request)
    {
        $msg = new MsgService;
        OA::Json(0, $msg->getmsglist());
    }


    /**
     *获取未读消息的总数
     */
    public function getmsgUnreadCount(Request $request)
    {
        $msg = new MsgService;
        OA::Json(0, $msg->getmsgUnreadCount());
    }





    /**
     * 获取最新系统消息id数组,用于本地判断系统消息是否已读
    */
    public function getsysmsg_id_Array(){
       $list= MsgSysModel::where('id','!=',0)
            ->orderBy('id','DESC')
           ->take(10)
           //->select(['id'])
          // ->get()->toArray();
            ->pluck('id')
                ->all();
       return $list;
    }









}
